package com.feishi.project.test;

import javax.swing.*;
import javax.swing.border.Border;
import java.awt.*;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: caixq
 * Date: 2019-08-08
 * Time: 上午11:46
 */
public class Panel  extends JFrame {

    public Panel(int x, int y) {
        setSize(x,y);
    }

    public void drawLine(int left, int top, int x, int y, int width, int height){
        Container containerPane = getContentPane();
        containerPane.add(new JPanel() {
            //重写
            @Override
            protected void paintComponent(Graphics g) {
                super.paintComponent(g);
                //竖线
                for (int i = 0; i <= x; i++) {
                    g.drawLine(width/x*i+left, 0+top, width/x*i+left, height+top);
                }
                //横线
                for (int i = 0; i <= y; i++) {
                    g.drawLine(+left, height/y*i+top, width+left, height/y*i+top);
                }
            }
        },BorderLayout.CENTER);
    }
    public Label[][] addChessboard( int x, int y){
        JPanel chessboard = new JPanel();
        GridLayout grid = new GridLayout(x, y);

        Label[][] label = new Label[x][y];
        chessboard.setLayout(grid);
        add(chessboard);

        Border border = BorderFactory.createLineBorder(Color.BLACK);

        for (int i = 0; i < label.length; i++) {
            for (int j = 0; j < label[i].length; j++) {
                Label l = new Label();
                Rectangle r = new Rectangle();

                l.setBounds(new Rectangle());
                label[i][j] = l;
//                label[i][j].setBackground((i+j)%3==0?Color.WHITE:((i+j)%3==1?Color.BLACK:Color.BLUE) );
                label[i][j].setBackground((i+j)%2==0?Color.WHITE:Color.BLACK );
                label[i][j].setBackground(Color.WHITE);
                chessboard.add(label[i][j]);
            }
        }
        return label;

    };
}
